#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QMenuBar* menuBar = this->menuBar();
    this->setMenuBar(menuBar);

//    // 创建并设置菜单
//    QMenu* menu1 = new QMenu("文件(&F)");
//    QMenu* menu2 = new QMenu("编辑(&E)");
//    QMenu* menu3 = new QMenu("构建(&B)");
//    QMenu* menu4 = new QMenu("帮助(&H)");

//    menuBar->addMenu(menu1);
//    menuBar->addMenu(menu2);
//    menuBar->addMenu(menu3);
//    menuBar->addMenu(menu4);

//    // 创建并设置菜单项
//    QAction* act1 = new QAction("菜单项1(&Q)");
//    QAction* act2 = new QAction("菜单项2(&W)");
//    QAction* act3 = new QAction("菜单项3(&E)");
//    QAction* act4 = new QAction("菜单项4(&R)");

//    menu1->addAction(act1);
//    menu2->addAction(act2);
//    menu3->addAction(act3);
//    menu4->addAction(act4);

//    // 关联槽函数
//    connect(act1, &QAction::triggered, this, &MainWindow::handle1);
//    connect(act2, &QAction::triggered, this, &MainWindow::handle2);
//    connect(act3, &QAction::triggered, this, &MainWindow::handle3);
//    connect(act4, &QAction::triggered, this, &MainWindow::handle4);

    // 菜单嵌套子菜单
    QMenu* menuParent = new QMenu("父菜单");
    QMenu* menuChild = new QMenu("子菜单");
    QMenu* menu1 = new QMenu("菜单一");

    QAction* act1 = new QAction("新建");
    QAction* act2 = new QAction("保存");
    QAction* act3 = new QAction("另存为");
    QAction* act4 = new QAction("属性");

    menuChild->addAction(act4);

    // 添加分割符
    menuParent->addAction(act1);
    menuParent->addSeparator();
    menuParent->addAction(act2);
    menuParent->addSeparator();
    menuParent->addAction(act3);
    menuParent->addSeparator();
    menuParent->addMenu(menuChild);

    menuBar->addMenu(menuParent);
    menuBar->addMenu(menu1);
}

MainWindow::~MainWindow()
{
    delete ui;
}

//void MainWindow::handle1()
//{
//    qDebug() << "handle1";
//}

//void MainWindow::handle2()
//{
//    qDebug() << "handle2";
//}

//void MainWindow::handle3()
//{
//    qDebug() << "handle3";
//}

//void MainWindow::handle4()
//{
//    qDebug() << "handle4";
//}


